package com.cloud.bc.controller;

import cn.hutool.json.JSONObject;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcSingles;
import com.cloud.bc.service.BcSinglesService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("m/center/notice")
@AllArgsConstructor
public class MCenterNoticeController extends BaseController {
    private final BcSinglesService bcSinglesService;
    /**
     * 系统消息
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request,"系统消息", "m/center/notice/index");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcSingles bcSingles = bcSinglesService.selectOne(new BcSingles().setUserId(userInfo.getId()));
        if (null != bcSingles) {
            JSONObject jsonSingle = new JSONObject();
            jsonSingle.put("user_id", bcSingles.getUserId());
            jsonSingle.put("photo", bcSingles.getPhoto());
            jsonSingle.put("pic", bcSingles.getPhoto());
            jsonSingle.put("nickname", bcSingles.getNickname());
            jsonSingle.put("check", bcSingles.getIsCheck());
            jsonSingle.put("close", bcSingles.getIsClose());
            view.addObject("userObj", jsonSingle.toString());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", "1");
        jsonObject.put("pic", "/m/img/logo.jpg");
        jsonObject.put("nickname", "51找朋友");
        jsonObject.put("user_id", "-1");
        view.addObject("targetObj", jsonObject.toString());
        return view;
    }
}
